import pygame
from game_items import *
class HUdPanel(object):
    """指示器面板类"""
    margin = 10                                 # 精灵之间的间距
    white = (255, 255, 255)                     # 白色
    gray = (64, 64, 64)                         # 灰色
    def __init__(self, display_group):
        """构造方法
        :param display_group: 面板中的精灵要被添加到的显示精灵组
        """
        # 游戏属性
        self.score = 0                          # 游戏得分
        self.lives_count = 3                    # 生命计数
        self.level = 1                          # 游戏级别
        self.best_score = 0                     # 最好成绩
        # 创建图像精灵
        # 状态精灵
        self.status_sprite = StatusButton(("pause.png", "resume.png"), display_group)
        self.status_sprite.rect.topleft = (self.margin, self.margin)
        # 炸弹精灵
        self.bomb_sprite = GameSprite("bomb.png", 0, display_group)
        self.bomb_sprite.rect.x = self.margin
        self.bomb_sprite.rect.bottom = SCREEN_RECT.bottom - self.margin
        # 生命计数精灵
        self.lives_sprite = GameSprite("life.png", 0, display_group)
        self.lives_sprite.rect.right = SCREEN_RECT.right - self.margin
        self.lives_sprite.rect.bottom = SCREEN_RECT.bottom - self.margin
        # 创建标签精灵
        # 分数标签
        self.score_label = Label("%d" % self.score, 32, self.gray, display_group)
        self.score_label.rect.midleft = (self.status_sprite.rect.right + self.margin,
                                         self.status_sprite.rect.centery)
        # 炸弹标签
        self.bomb_label = Label("X 3", 32, self.gray, display_group)
        self.bomb_label.rect.midleft = (self.bomb_sprite.rect.right + self.margin,
                                        self.bomb_sprite.rect.centery)
        # 生命计数标签
        self.lives_label = Label("X %d" % self.lives_count, 32, self.gray, display_group)
        self.lives_label.rect.midright = (SCREEN_RECT.right - self.margin,
                                          self.bomb_label.rect.centery)
        # 调整生命计数精灵位置
        self.lives_sprite.rect.right = self.lives_label.rect.left - self.margin
        # 最好成绩标签
        self.best_label = Label("Best: %d" % self.best_score, 36, self.white, display_group)
        self.best_label.rect.center = SCREEN_RECT.center
        # 状态标签
        self.status_label = Label("Game Over!", 48, self.white, display_group)
        self.status_label.rect.midbottom = (self.best_label.rect.centerx,
                                            self.best_label.rect.y - 2 * self.margin)
        # 提示标签
        self.tip_label = Label("Press spacebar to play again.", 22, 
                                self.white, display_group)
        self.tip_label.rect.midtop = (self.best_label.rect.centerx,
                                      self.best_label.rect.bottom + 8 * self.margin)

